package cn.masterj.springcloud.controller;

import cn.masterj.springcloud.CommonResult;
import cn.masterj.springcloud.entity.Storage;
import cn.masterj.springcloud.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author masterJ
 * @create 2020-04-20 17:40
 */
@RestController
public class StorageController {

    @Autowired
    private IStorageService storageService;

    @GetMapping("/storage/getById/{id}")
    public CommonResult<Storage> getById(@PathVariable("id") Long id){
        Storage storage = storageService.getById(id);
        return new CommonResult<>(200,"查询成功", storage);
    }


    /**
     * 测试库存减一
     * @return
     */
    @GetMapping("/storage/decrease")
    public CommonResult<Storage> decrease(@RequestParam("id") Long id){
        Storage storage = storageService.getById(id);
        storage.setNum(storage.getNum() - 1);
        storageService.updateById(storage);
        return new CommonResult<>(200,"库存减一成功", storage);
    }



}

